<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    $(document).ready(function() {
        if($("#updateForm").length>0){ /**判断当前页面是否有填写表单并检验**/
        	validateUpdateForm();
            /**Modal验证销毁重构**/
            $('#updateForm').on('hidden.bs.modal', function() {
                reValidateUpdateTatioForm();
            });
        }
    });

    function reValidateUpdateTatioForm(){
        $("#updateForm").data('bootstrapValidator', null);
        validateUpdateForm();
    }

    /**
     * 自定义验证规则
     */
    function validateUpdateForm(){
        $("#updateForm").bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                upRatio: {
                    validators: {
                        notEmpty: {message: "一级返利不可为空"},
                        stringLength: {max: 20,message: "一级返利最大长度为20"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                },
                secRatio: {
                    validators: {
                        notEmpty: {message: "二级返利不可为空"},
                        stringLength: {max: 20, message: "二级返利最大长度为20"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                },
                thiRatio: {
                    validators: {
                        notEmpty: {message: "三级返利不可为空"},
                        stringLength: {max: 20, message: "三级返利最大长度为20"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                }
            }
        });
    }

    /**提交商品审核表单信息**/
    var isValid;
    function submitForUpdateProduct(){
        /** 开启验证**/
        $("#updateForm").data('bootstrapValidator').validate().validate();
        isValid=$("#updateForm").data('bootstrapValidator').isValid();
        if(isValid){  /** 验证通过后提交表单**/
        var options = {
                url: $("#updateForm").attr("action"),
                type : "post",
                dataType:"json",
                success : function(data) {
                    if(data.success==true){
                        /** 自动关闭弹出模态框窗口**/
                        $(".close").click();
                        $("#tt").bootstrapTable('refresh');
                        showMsg("保存成功！");
                    }else{
                        showMsg("保存失败！");
                    }
                }
            };
            $("#updateForm").ajaxSubmit(options);
        }else{ /** 验证失败了直接返回 **/
            return false;
        }
	}

</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button id="addOrEditBtn" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="updateModalLabel"></h5>
			</div>

			<!--商品修改返利比例开始-->
			<div class="modal-body">
				<form id="updateForm" method="post" action="${basePath}/back/shopProduct/updateProductRatio.sjson">
					<input id="ur_productId" type="hidden" name="productId" value="">
					<table align="center" class="addOrEditTable" width="100%;" style="margin-left:50px;">
						<tr>
							<td class="toright_td" width="150px"><font color="Red"> *</font>上一级返利比例（%）:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<div class="form-group">
									<input id="ur_upRatio" class="form-control input-sm" type="text" name="upRatio" />
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><font color="Red"> *</font>上一级返利比例（%）:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<div class="form-group">
									<input id="ur_secRatio" class="form-control input-sm" type="text" name="secRatio"  />
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><font color="Red"> *</font>上一级返利比例（%）:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<div class="form-group">
									<input id="ur_thiRatio" class="form-control input-sm" type="text" name="thiRatio" />
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<!--商品修改返利比例结束-->

			<div class="modal-footer">
				<button type="button" id="saveBtn" class="btn btn-primary"  onclick="submitForUpdateProduct()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
